<?php 

require_once("../shared/connect.php");

$read = mysql_query("SELECT DISTINCT location.id, location.assoc_id, location.van, location.type, 
							location.address, location.num_people, location.total_wait, 
							location.start_time, location.last_updated, geocode.lat, geocode.lng
					 FROM location LEFT JOIN geocode
					 ON location.address = geocode.full_address
					 WHERE location.van = '$_GET[van]'
					 ORDER BY location.id") 
		or die(mysql_error());

$out = "\"length\": ".mysql_num_rows($read).', "rows": { ';

while ($row = mysql_fetch_assoc($read)) {
	//$row[total_wait] += (time() - $row[start_time]);
	$out .= "\"$row[id]\": ".json_encode($row).",";
}

$out = substr_replace($out ,"",-1); // strip trailing comma. beware of case mysql_num_rows == 0

echo '{'.$out.'}}';

?>